#	$OpenBSD: Makefile.bsd-wrapper,v 1.8 2013/08/06 19:11:53 miod Exp $

LIB=		objc


LIBIBERTY_INCLUDES=${.CURDIR}/../libiberty/include
.include <bsd.own.mk>
.if make(obj)
.else
. if ${COMPILER_VERSION:L} == "gcc3"
GCCDIR= $(.CURDIR)/../../usr.bin/gcc
GCCSRCDIR=${GCCDIR}/gcc
. else
error wrong compiler
. endif
.endif

.if defined(MAKEOBJDIR)
OBJDIR= ${MAKEOBJDIR}
.elif defined(OBJMACHINE)
OBJDIR=	obj.${MACHINE}
.else
OBJDIR=	obj
.endif
GCCOBJDIR!=	if [ -d $(GCCDIR)/$(OBJDIR) ]; then \
			echo $(GCCDIR)/$(OBJDIR); \
		else \
			echo $(GCCDIR); \
		fi

GNUCFLAGS=	${CFLAGS} ${COPTS} -DOPENBSD_NATIVE
		

MAKE_FLAGS= 	CFLAGS="${GNUCFLAGS}" \
		CC="${CC}" LDFLAGS="${LDSTATIC}" \
		LIBIBERTY_INCLUDES=${LIBIBERTY_INCLUDES} \
		CPPFLAGS=${CPPFLAGS} \
		GCCSRCDIR=${GCCSRCDIR} \
		GCCOBJDIR=${GCCOBJDIR}

CPPFLAGS+= -I. -I${.CURDIR}/libobjc -I$(.CURDIR)/libobjc/objc  -I$(GCCSRCDIR) \
-I$(GCCSRCDIR)/config  -I$(GCCOBJDIR) -I$(LIBIBERTY_INCLUDES) \
-DIN_GCC -DIN_TARGET_LIBS

SRCS=archive.c class.c encoding.c gc.c hash.c init.c linking.m misc.c \
nil_method.c NXConstStr.m Object.m objects.c Protocol.m sarray.c  \
selector.c sendmsg.c thr.c 

SRCS+=thr-posix.c

includes:
	install -d -m 755 -o $(BINOWN) -g $(BINGRP) \
		$(DESTDIR)/usr/include/objc
	@-cd $(.CURDIR)/libobjc/objc; for i in *.h; do \
		[ $$i = "runtime.h" ] || install -C -o $(BINOWN) -g $(BINGRP) -m $(NONBINMODE) \
				$$i $(DESTDIR)/usr/include/objc/$$i; \
	done

depend: 
	cd ${GCCDIR} && exec ${MAKE} -f Makefile.bsd-wrapper config.status target_path tconfig.h

sendmsg.o sendmsg.go sendmsg.po sendmsg.so: runtime-info.h

runtime-info.h:
		echo "" > tmp-runtime
		echo "/* This file is automatically generated */" > $@
		`$(CC) -print-prog-name=cc1obj` -print-objc-runtime-info tmp-runtime >> $@
		rm -f tmp-runtime

.ifdef GLOBAL_AUTOCONF_CACHE
CF=	--cache-file=${GLOBAL_AUTOCONF_CACHE}
.else
CF=
.endif

config.status: libobjc/Makefile.in libobjc/configure
	PATH="/bin:/usr/bin:/sbin:/usr/sbin" \
	INSTALL_PROGRAM="${INSTALL} ${INSTALL_COPY} ${INSTALL_STRIP}" \
	GCCDIR=${GCCDIR} \
	/bin/sh ${.CURDIR}/libobjc/configure --with-gnu-as --with-gnu-ld \
		--prefix=/usr --mandir='$$(prefix)/share/man' \
		--enable-shared \
		--with-local-prefix=/usr ${CF} \
		&& touch config.status

.ifdef NOMAN
maninstall:
	@echo NOMAN is set
.endif

depend: 

lint:
	# Nothing here so far...

tags:
	# Nothing here so far...

.include <bsd.obj.mk>
.ifndef NOMAN
.include <bsd.man.mk>
.endif
.include <bsd.lib.mk>

.SUFFIXES:	.m

.PATH:	${.CURDIR}/libobjc

COMPILE.m=${COMPILE.c} -fgnu-runtime

gc.o: gc.c
	@echo "${COMPILE.c} ${.ALLSRC} -o ${.TARGET}"
	@${COMPILE.c} ${.ALLSRC}  -o ${.TARGET}.o
	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
	@rm -f ${.TARGET}.o
	
gc.go: gc.c
	@echo "${COMPILE.c} -g ${.ALLSRC} -o ${.TARGET}"
	@${COMPILE.c} -g ${.ALLSRC} -o ${.TARGET}.o
	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
	@rm -f ${.TARGET}.o

gc.po: gc.c
	@echo "${COMPILE.c} -p ${.ALLSRC} -o ${.TARGET}"
	@${COMPILE.c} -p ${.ALLSRC} -o ${.TARGET}.o
	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
	@rm -f ${.TARGET}.o

gc.so: gc.c
	@echo "${COMPILE.c} ${PICFLAG} -DPIC ${.ALLSRC} -o ${.TARGET}"
	@${COMPILE.c} ${PICFLAG} -DPIC ${.ALLSRC} -o ${.TARGET}.o
	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
	@rm -f ${.TARGET}.o

.m.o:
	@echo "${COMPILE.m} ${.IMPSRC} -o ${.TARGET}"
	@${COMPILE.m} ${.IMPSRC}  -o ${.TARGET}.o
	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
	@rm -f ${.TARGET}.o

.m.go:
	@echo "${COMPILE.m} -g ${.IMPSRC} -o ${.TARGET}"
	@${COMPILE.m} -g ${.IMPSRC} -o ${.TARGET}.o
	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
	@rm -f ${.TARGET}.o

.m.po:
	@echo "${COMPILE.m} -p ${.IMPSRC} -o ${.TARGET}"
	@${COMPILE.m} -p ${.IMPSRC} -o ${.TARGET}.o
	@${LD} -X -r ${.TARGET}.o -o ${.TARGET}
	@rm -f ${.TARGET}.o

.m.so:
	@echo "${COMPILE.m} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}"
	@${COMPILE.m} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
	@rm -f ${.TARGET}.o

